package com.stm.quartz.task;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import org.springframework.stereotype.Component;

/**
 * 定时任务调度测试
 * 
 * @author admin
 */
@Component("ryTask")
public class RyTask
{
    public void ryParams(String params) throws IOException, InterruptedException
    {
    	
        try {
            URL url = new URL("http://"+params+"/api/v1/Search?type=record&start=2018-0307T120101%2b08&end=3019-05-18T130101%2b08&token=token1&session=");
            InputStream in =url.openStream();
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader bufr = new BufferedReader(isr);
            System.out.println("验证视频软件是否工作");
            bufr.close();
            isr.close();
            in.close();
        } catch (Exception e) {
        	restart(params); //执行视频重启
            e.printStackTrace();
        }
    	
//        System.out.println("执行有参方法：" + params);
    }
    public void restart(String params) throws IOException, InterruptedException
    {
    	String osName = System.getProperty("os.name", "");
    	if (osName.startsWith("Windows")) {
    		
    		
    		Runtime runtime = Runtime.getRuntime();
    		Process process = runtime.exec("c:/nircmd.exe elevate net stop H5Stream");
    		process.waitFor();
    		
    		Runtime runtime1 = Runtime.getRuntime();
    		Process process1 = runtime1.exec("c:/nircmd.exe elevate net start H5Stream");
    		process1.waitFor();
    		
    	}else{
    		
    		Runtime.getRuntime().exec(new String[]{"/bin/sh","-c","systemctl restart h5ss.service"});
    	}
    	 System.out.println("视频软件重启成功");
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
}
